package cn.rkylin.oms.aftersale.sysreturn.dao.impl;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.aftersale.sysreturn.dao.ISysReturnDAO;
import cn.rkylin.oms.aftersale.sysreturn.domain.SysReturn;
import cn.rkylin.oms.aftersale.sysreturn.vo.SysReturnVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类名:SysReturnDAOImpl <br/>
 * 作用: 退货单数据访问类. <br/>
 * 创建原因:	 退货单数据库访问操作. <br/>
 * 创建时间:     2017年9月28日 下午8:18:58 <br/>
 *
 * @author zhanghao
 * @version v1.0
 */
@Repository("sysReturnDAO")
public class SysReturnDAOImpl implements ISysReturnDAO {
    @Autowired
    IDataBaseFactory dao;

    private String STATEMENT_INSERT_SELECTIVE = "insertSelectiveSysReturn";
    private String STATEMENT_UPDATE_SELECTIVE = "updateSelectiveSysReturn";

    private String STATEMENT_UPDATE_UN_APPR_SYS_RETURN = "updateUnApprExtSysReturn";

    private String STATEMENT_SELECT_SELECTIVE = "selectSelectiveSysReturn";
    private String STATEMENT_SELECT_SELECTIVE_EXTEND = "selectSelectiveSysReturnExtend";

    private String STATEMENT_UPDATE_CANCEL_EXT = "updateCancelExtSysReturn";
    private String STATEMENT_UPDATE_CANCEL_LOCAL = "updateCancelLocalSysReturn";

    private String STATEMENT_SELECT_DETAIL_BY_PRIMARYKEY = "selectByPrimaryKeySysReturnDetail";

    private String STATEMENT_SELECT_COUNT_BY_STATUS = "selectSysReturnCountByStatus";

    private String STATEMENT_SELECT_BY_PRIMARYKEY = "selectByPrimaryKeySysReturn";

    private String STATEMENT_SELECT_BY_SOURCEID = "selectSysReturnCancelBySourceId";
    private String STATEMENT_SELECT_RETURN_COUNT_BY_REFUND_ID = "selectReturnCountByRefundId";

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#deleteByPrimaryKey(java.lang.String)
     */
    @Override
    public int deleteByPrimaryKey(String returnId) {

        return 0;
    }

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#insert(cn.rkylin.oms.sysreturn.domain.SysReturn)
     */
    @Override
    public int insert(SysReturn record) {

        return 0;
    }

    /**
     * 退货单新增操作.
     *
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#insertSelective(cn.rkylin.oms.sysreturn.domain.SysReturn)
     */
    @Override
    public int insertSelective(SysReturn record) throws Exception {
        return dao.insert(STATEMENT_INSERT_SELECTIVE, record);
    }

    /**
     * 通过ID获取单条退货单信息(带明细的)
     *
     * @param returnId
     * @return
     * @throws Exception
     */
    @Override
    public SysReturnVO selectByPrimaryKey(String returnId) throws Exception {
        return dao.findOne(STATEMENT_SELECT_DETAIL_BY_PRIMARYKEY, returnId);
    }

    /**
     * 通过ID获取单条退货单信息
     *
     * @param returnId
     * @return
     * @throws Exception
     */
    @Override
    public SysReturnVO selectByPrimaryKeyOnly(String returnId) throws Exception {
        return dao.findOne(STATEMENT_SELECT_BY_PRIMARYKEY, returnId);
    }

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#updateByPrimaryKeySelective(cn.rkylin.oms.sysreturn.domain.SysReturn)
     */
    @Override
    public int updateByPrimaryKeySelective(SysReturn record) {
        // TODO Auto-generated method stub
        return 0;
    }

    /**
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#updateByPrimaryKey(cn.rkylin.oms.sysreturn.domain.SysReturn)
     */
    @Override
    public int updateByPrimaryKey(SysReturn record) {

        return 0;
    }

    /**
     * 退货单更新/删除操作.
     *
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#updateBySelective(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public int updateBySelective(SysReturnVO record) throws Exception {
        return dao.update(STATEMENT_UPDATE_SELECTIVE, record);
    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#selectBySelectiveValue(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public List<SysReturnVO> selectBySelectiveValue(SysReturnVO sysReturnVO) throws Exception {
        return dao.findAllList(STATEMENT_SELECT_SELECTIVE, sysReturnVO);

    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#cancelSysReturn4Ext(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public int cancelSysReturn4Ext(SysReturnVO param) throws Exception {
        return dao.update(STATEMENT_UPDATE_CANCEL_EXT, param);
    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#cancelSysReturn4Local(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public int cancelSysReturn4Local(SysReturnVO param) throws Exception {
        return dao.update(STATEMENT_UPDATE_CANCEL_LOCAL, param);
    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#updateUnApproveSysReturn(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public int updateUnApproveSysReturn(SysReturnVO param) throws Exception {
        return dao.update(STATEMENT_UPDATE_UN_APPR_SYS_RETURN, param);
    }

    /**
     * @throws Exception
     * @see cn.rkylin.oms.sysreturn.dao.ISysReturnDAO#selectBySelectiveValueExtend(cn.rkylin.oms.sysreturn.vo.SysReturnVO)
     */
    @Override
    public List<SysReturnVO> selectBySelectiveValueExtend(SysReturnVO queryParam) throws Exception {
        return dao.findAllList(STATEMENT_SELECT_SELECTIVE_EXTEND, queryParam);
    }

    /**
     * 按条件查询退货单信息列表(分页)
     *
     * @param page
     * @param length
     * @param queryParamVO
     * @return
     * @throws Exception
     */
    public PageInfo<SysReturnVO> pageSelectByCondition(int page, int length, SysReturnVO queryParamVO) throws Exception {
        PageInfo<SysReturnVO> returnObject = dao.findPage(page, length, STATEMENT_SELECT_SELECTIVE, queryParamVO);
        return returnObject;
    }

    /**
     * 获取退货单各个Tab页单据数量
     *
     * @param queryParamVO
     * @return
     * @throws Exception
     */
    public List<HashMap> selectStateCount(SysReturnVO queryParamVO) throws Exception {
        return dao.find(STATEMENT_SELECT_COUNT_BY_STATUS, queryParamVO);
    }

    /**
     * 通过来源ID获取退货单信息
     *
     * @param sourceId
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnVO> selectBySourceID(String sourceId) throws Exception {
        return dao.findList(STATEMENT_SELECT_BY_SOURCEID, sourceId);
    }

    /**
     * 通过退款单ID获取退货单数量（通过oid关联）
     *
     * @param refundId
     * @return
     * @throws Exception
     */
    @Override
    public Integer selectReturnCountByRefundId(String refundId) throws Exception {
        return dao.findOne(STATEMENT_SELECT_RETURN_COUNT_BY_REFUND_ID, refundId);
    }

    /**
     * 判断 仓库入库单号 是否存在
     *
     * @param sysReturn
     * @return
     * @throws Exception
     */
    @Override
    public List<SysReturnVO> selectSysReturnWmsStockinCode(SysReturn sysReturn) throws Exception {
        return dao.find("selectSysReturnWmsStockinCode", sysReturn);
    }

    @Override
    public int getUnGoingCount(Map<String, String> paramMap) throws Exception {
        return dao.findOne("selectUnGoingReturnCount", paramMap);
    }
}

